﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using WinAppWeChartDemo.Models;

namespace WinAppWeChartDemo.Common
{
    public class MessageQueue
    {
        private readonly static Queue<MessageQueueModel> messageQueue = new Queue<MessageQueueModel>();
        /// <summary>
        /// 添加一条消息到队列
        /// </summary>
        /// <param name="msg"></param>
        public void AddMessgae(MessageQueueModel msg)
        {
            lock (this)
            {
                messageQueue.Enqueue(msg);
            }
        }

        public MessageQueueModel GetMessage()
        {
            MessageQueueModel msg = default(MessageQueueModel);
            lock (this)
            {
                msg = messageQueue.Dequeue();
            }
            return msg;
        }

        public bool IsMessageQueueAvailable => messageQueue.Count > 0;
    }
}
